home *** CD-ROM | disk | FTP | other *** search
/ Suzy B Software 2 / Suzy B Software CD-ROM 2 (1994).iso / extras / programm / gemfsc20 / gemfsc20.lzh / GEMFUNCS / RSCCUBTN.C < prev    next >
C/C++ Source or Header  |  1993-03-20  |  7KB  |  232 lines

  1. /**************************************************************************
  2.  * RSCCUBTN.C - The rsc_cubuttons() routine.
  3.  *     This changes the specified objects into CUA-style selection & radio
  4.  *     buttons (by making them USERDEF objects), and supplies the drawing
  5.  *     routine for the buttons.
  6.  *************************************************************************/
  7.  
  8. #include "gemfintl.h"
  9.  
  10. typedef struct {
  11.     short wchar;
  12.     short hchar;
  13.     short outer_radius;
  14.     short inner_radius;
  15.     short text_xoffs;
  16.     short text_yoffs;
  17.     short circle_xoffs;
  18.     short circle_yoffs;
  19.     short box_xoffs;
  20.     short box_yoffs;
  21.     short box_xsize;
  22.     short box_ysize;
  23. } PreCalcs;
  24.  
  25. static PreCalcs GFAR precalcs;
  26.  
  27. /*-------------------------------------------------------------------------
  28.  * init_precalcs - Fill in the precalculated values structure.
  29.  *-----------------------------------------------------------------------*/
  30.  
  31. #ifdef GEMFAST_PROTOS
  32.   static void init_precalcs(void)
  33. #else
  34.   static void init_precalcs()
  35. #endif
  36. {
  37.     register PreCalcs  *pc;
  38.     register short        wchar;
  39.     register short        hchar;
  40.     register short        h8;
  41.     register short        aspectx;
  42.     register short        aspecty;
  43.  
  44.     pc        = &precalcs;
  45.     wchar    = gl_wchar;
  46.     hchar    = gl_hchar;
  47.     h8        = hchar / 8;
  48.     aspectx = gl_vwout[3];
  49.     aspecty = gl_vwout[4];
  50.  
  51.     pc->wchar         = wchar;
  52.     pc->hchar         = hchar;
  53.  
  54.     pc->text_xoffs     = wchar * 3;
  55.     pc->text_yoffs     = 0;
  56.  
  57.     pc->box_ysize     = hchar - h8;
  58.     pc->box_xsize     = (pc->box_ysize * aspecty) / aspectx;
  59.     pc->box_xoffs     = 1;
  60.     pc->box_yoffs     = 0;
  61.  
  62.     pc->outer_radius = ((hchar * aspecty) / aspectx) / 2;
  63.     pc->inner_radius = pc->outer_radius / 2;
  64.     pc->circle_xoffs = pc->outer_radius + pc->box_xoffs;
  65.     pc->circle_yoffs = (hchar / 2) - h8;
  66.  
  67. }
  68.  
  69. /*-------------------------------------------------------------------------
  70.  * cua_draw - Draw a CUA-style button.    This routine is called by
  71.  *              the AES whenever a CUA-style button needs to be drawn
  72.  *              or to have its state changed.  (Note that this routine
  73.  *              gets control in supervisor mode.    Some runtime libraries
  74.  *              will crash on stack overlow problems if you make calls
  75.  *              to DOS, BIOS, or XBIOS from in here.)
  76.  *
  77.  *              We handle SELECTED, CROSSED, OUTLINED, and DISABLED states
  78.  *              here, but other states are handled by the AES because we
  79.  *              pass the states we didn't do back to the AES as the return
  80.  *              value from this routine.
  81.  *-----------------------------------------------------------------------*/
  82.  
  83. #ifdef GEMFAST_PROTOS
  84.   static long GCALLBACK cua_draw(XPARMBLK *parmblk)
  85. #else
  86.   static long GCALLBACK cua_draw(parmblk)
  87.     register XPARMBLK  *parmblk;
  88. #endif
  89. {
  90.     register PreCalcs  *pc = &precalcs;
  91.     short                dmy;
  92.     register short        xpos;
  93.     register short        ypos;
  94.     register short        vdi_handle;
  95.     register short        objstate;
  96.     VRECT                boxrect;
  97.     VRECT                cliprect;
  98.  
  99.     if (0 == (vdi_handle = apl_vshared())) {
  100.         return 0;    /* oh well, so sorry */
  101.     }
  102.  
  103.     objstate = parmblk->currstate;
  104.  
  105.     rc_gtov(&parmblk->cliprect, &cliprect);
  106.     vs_clip(vdi_handle, 1, (short *)&cliprect);
  107.     vsf_interior(vdi_handle, IS_HOLLOW);
  108.  
  109.     xpos = parmblk->drawrect.g_x;
  110.     ypos = parmblk->drawrect.g_y + ((parmblk->drawrect.g_h - pc->hchar) / 2);
  111.  
  112.     if (objstate & DISABLED) {
  113.         vst_effects(vdi_handle, 0x0002);
  114.     }
  115.     vst_alignment(vdi_handle, 0, 5, &dmy, &dmy);
  116.     v_gtext(vdi_handle, (xpos + pc->text_xoffs), (ypos + pc->text_yoffs),
  117.             (char *)parmblk->pub->ob_spec);
  118.     vst_alignment(vdi_handle, 0, 0, &dmy, &dmy);
  119.     if (objstate & DISABLED) {
  120.         vst_effects(vdi_handle, 0x0000);
  121.     }
  122.  
  123.     if (parmblk->ptree[parmblk->obj].ob_flags & RBUTTON) {
  124.         xpos += pc->circle_xoffs;
  125.         ypos += pc->circle_yoffs;
  126.         v_circle(vdi_handle, xpos, ypos, pc->outer_radius);
  127.         if (objstate & (SELECTED|CROSSED)) {
  128.             vsf_interior(vdi_handle, IS_SOLID);
  129.             v_circle(vdi_handle, xpos, ypos, pc->inner_radius);
  130.             vsf_interior(vdi_handle, IS_HOLLOW);
  131.         }
  132.     } else {
  133.         boxrect.v_x1 = xpos + pc->box_xoffs;
  134.         boxrect.v_y1 = ypos + pc->box_yoffs;
  135.         boxrect.v_x2 = boxrect.v_x1 + pc->box_xsize;
  136.         boxrect.v_y2 = boxrect.v_y1 + pc->box_ysize;
  137.         v_bar(vdi_handle, (short *)&boxrect);
  138.         if (objstate & (SELECTED|CROSSED)) {
  139.             register short temp;
  140.             v_pline(vdi_handle, 2, (short *)&boxrect);
  141.             temp         = boxrect.v_x1;
  142.             boxrect.v_x1 = boxrect.v_x2;
  143.             boxrect.v_x2 = temp;
  144.             v_pline(vdi_handle, 2, (short *)&boxrect);
  145.         }
  146.     }
  147.  
  148.     if (objstate & OUTLINED) {
  149.         rc_gtov(&parmblk->drawrect, &boxrect);
  150.         rc_vadjust(&boxrect, 3, 3);
  151.         vswr_mode(vdi_handle, MD_TRANS);
  152.         v_bar(vdi_handle, (short *)&boxrect);
  153.         vswr_mode(vdi_handle, MD_REPLACE);
  154.     }
  155.  
  156.     vsf_interior(vdi_handle, IS_SOLID);
  157.     vs_clip(vdi_handle, 0, (short *)&cliprect);
  158.  
  159.     return (objstate & ~(SELECTED|DISABLED|OUTLINED|CROSSED));
  160. }
  161.  
  162. /*-------------------------------------------------------------------------
  163.  * rsc_cubuttons - Transform all non-exit buttons in a tree to CUA-style.
  164.  *-----------------------------------------------------------------------*/
  165.  
  166. short rsc_cubuttons(ptree)
  167.     OBJECT              *ptree;
  168. {
  169.     register OBJECT   *pobj;
  170.     register XUSERBLK *pblk;
  171.     register short         obflags;
  172.     register short         numobj = 0;
  173.     register short         curobj;
  174.  
  175. /*
  176.  * do setup stuff...
  177.  */
  178.  
  179.     if (0 == apl_vshared()) {    /* force open shared workstation, also    */
  180.         return gfErr_vdi_handle;             /* tests to make sure one is available. */
  181.     }
  182.  
  183.     if (precalcs.outer_radius == 0) {    /* this must follow apl_vshared() */
  184.         init_precalcs();
  185.     }
  186.  
  187. /*
  188.  * count the number of button objects we'll be transforming...
  189.  */
  190.  
  191.     for (pobj = ptree; ; ++pobj) {
  192.         obflags = pobj->ob_flags;
  193.         if ((pobj->ob_type & 0x00FF) == G_BUTTON
  194.          && !(obflags & (EXIT|DEFAULT))) {
  195.             ++numobj;
  196.         }
  197.         if (obflags & LASTOB) {         /* stop after doing last    */
  198.             break;                        /* object in the tree.        */
  199.         }
  200.     }
  201.  
  202.  
  203. /*
  204.  * allocate a chunk of memory to hold all the XUSERBLKs we're going
  205.  * to attach to the objects.
  206.  */
  207.  
  208.     if (NULL == (pblk = apl_malloc((long)(numobj * sizeof(XUSERBLK))))) {
  209.         return gfErr_no_memory;
  210.     }
  211.  
  212. /*
  213.  * now go through and change each non-exit button object into a USERDEF.
  214.  */
  215.  
  216.     for (curobj = 0, pobj = ptree; ; ++curobj, ++pobj) {
  217.         obflags = pobj->ob_flags;
  218.         if ((pobj->ob_type & 0x00FF) == G_BUTTON
  219.          && !(obflags & (EXIT|DEFAULT))) {
  220.             obj_mxuserdef(ptree, curobj, pblk++, cua_draw, NULL, 0L);
  221.         }
  222.         if (obflags & LASTOB) {         /* stop after doing last    */
  223.             break;                        /* object in the tree.        */
  224.         }
  225.     }
  226.  
  227.     return 0;
  228. }
  229.  
  230.  
  231.  
  232.